package com.h3c.nem.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.h3c.nem.dto.beisen.BeiSenBuildDTO;
import com.h3c.nem.service.BeiSenService;
import io.swagger.annotations.Api;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "北森接口")
@Slf4j
@RestController
@CrossOrigin
@RequestMapping(value = "/beiSen",produces = "application/json;charset=utf-8")
public class BeiSenController {

    @Resource
    private BeiSenService beiSenService;

    //测试接口
    @GetMapping("/getBeiSenOffer")
    public ResponseEntity<JSONObject> getBeiSenOffer(@RequestParam(name = "beiSenNumber") String beiSenNumber) {
        beiSenService.getBeiSenOffer(beiSenNumber);
        return new ResponseEntity<>(HttpStatus.ACCEPTED);
    }
    //测试接口
    @GetMapping("/getBeiSenInfo")
    public ResponseEntity<JSONObject> getBeiSenInfo(@RequestParam(name = "beiSenNumber") String beiSenNumber) {
        beiSenService.getBeiSenInfo(beiSenNumber);
        return new ResponseEntity<>(HttpStatus.ACCEPTED);
    }
    //测试接口
    @GetMapping("/buildBeiSenDTO")
    public ResponseEntity<JSONObject> buildBeiSenDTO(@RequestParam(name = "beiSenNumber") String beiSenNumber) {
        BeiSenBuildDTO buildDTO = beiSenService.buildBeiSenDTO(beiSenNumber);
//        beiSenService.idCardOcr("http://10.165.8.176:8080/DDQInfo/%E4%BB%98%E6%80%BB%E8%BA%AB%E4%BB%BD%E8%AF%81%E5%A4%8D%E5%8D%B0.jpg?AWSAccessKeyId=QWWXTI7RTP64STC4PT6U&Expires=1657701640&Signature=FAf1ofsjbrXA4of%2BcWi8SNyRs9o%3D");
        return new ResponseEntity<>(JSONObject.parseObject(JSONObject.toJSONStringWithDateFormat(buildDTO, "yyyy-MM-dd")), HttpStatus.ACCEPTED);
    }


    //测试
    @GetMapping("/syncPreWorkerIdToBeiSen")
    public ResponseEntity<JSONObject> syncPreWorkerIdToBeiSen(@RequestParam(name = "beiSenNumber") String beiSenNumber,
                                                              @RequestParam(name = "preWorkerId") String workerId,
                                                              @RequestParam(name = "errorMsg") String errorMsg) {
        beiSenService.syncPreWorkerIdToBeiSen(beiSenNumber, workerId, errorMsg);
        return new ResponseEntity<>(HttpStatus.ACCEPTED);
    }

    @Data
    public static class ReqDTO {
        private List<String> personIds;
    }

    @PostMapping("/postUserIdList")
    public ResponseEntity<JSONArray> beiSenFunc(@RequestBody ReqDTO dto) {
        List<BeiSenService.ReturnDTO> func = beiSenService.func(dto.getPersonIds());
        JSONArray object = JSONObject.parseArray(JSONObject.toJSONString(func));
        return new ResponseEntity<>(object, HttpStatus.ACCEPTED);
    }

}
